package org.feng.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.feng.annotions.DataPermission;
import org.feng.entity.User;

import java.util.List;

/**
 * <p>
 * Mapper 接口
 * </p>
 *
 * @author fengjinsong
 * @since 2023-08-24
 */
@Mapper
public interface UserMapper extends BaseMapper<User> {

    /**
     * 验证：通过创建人id查用户，权限控制
     *
     * @return 创建人相同的人员列表
     */
    @Select("select * from mp_user")
    @DataPermission(permissionFieldName = "create_user_id")
    List<User> listUserByCreateUserId();


    /**
     * 验证：通过用户id查询用户，权限控制，rbac
     *
     * @return 用户列表
     */
    @Select("select * from mp_user")
    @DataPermission(permissionFieldName = "id", useRequestRole = true)
    List<User> listUserByRole();

    /**
     * 查询同一部门的所有人员id
     *
     * @param userId 用户id
     * @return 同部门人员id
     */
    @Select("select id from mp_user where dept_id = (select dept_id from mp_user where id = #{userId} limit 1)")
    List<Integer> listUserId(Integer userId);
}
